#include "gamerulepage.h"
#include "ui_gamerulepage.h"
#include "mainwindow.h"
#include "QPainter"
#include "QPaintEvent"
#include "QTimer"
#include "QSound"

#include "mypushbutton.h"

GameRulePage::GameRulePage(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::GameRulePage)
{
    ui->setupUi(this);
    //设置窗口标题
    this->setWindowTitle("六子棋小游戏");
    this->setFixedSize(2*MARGIN+(BOARD_GARD_SIZE-1)*BLOCK_SIZE+400,2*MARGIN+(BOARD_GARD_SIZE-1)*BLOCK_SIZE);
    this->setWindowIcon(QPixmap(":/res/logo2.jpg")); //设置应用图标

    //创建菜单栏
    QMenuBar * bar = menuBar();
    setMenuBar(bar);

    //创建开始菜单
    QMenu * startMenu = bar->addMenu("开始");

    //创建退出的菜单项
    QAction * quitAction = startMenu->addAction("退出");

    //点击退出，实现退出游戏
    connect(quitAction,&QAction::triggered,[=](){
        this->close();
    });

    //设置规则标签的大小、边框样式
    ui->label->setGeometry(10,10,1224,768);
    setStyleSheet("QLabel{border:2px solid rgb(200, 200, 200);}");


    ////////////////////用图片实现返回按钮////////////
        //返回按钮
        MyPushButton * backBtn3 = new MyPushButton(":/res/backBtnFinal.png");
        backBtn3->setParent(this);
        backBtn3->move(780 , 650);


        //点击返回
        connect(backBtn3,&MyPushButton::clicked,[=](){
            //qDebug() << "点击了返回按钮";

            //播放返回按钮音效
            QSound::play(":/res/button.wav");

            //做弹起特效
            backBtn3->zoom1();
            backBtn3->zoom2();

            QTimer::singleShot(500,this,[=](){
                emit this->GameRulePageBack();
            });
        });

}

void GameRulePage::paintEvent(QPaintEvent *){
    //设置背景图片
    //创建画家
    QPainter painter(this);
    painter.drawPixmap( 0 , 0 , this->width() , this->height() , QPixmap(":/res/newBackground.webp"));
}

GameRulePage::~GameRulePage()
{
    delete ui;
}
